import sqlexecx
from config import MYSQL

if __name__ == '__main__':
    select_key = "SELECT LAST_INSERT_ID()"
    sqlexecx.init(**MYSQL)
    sqlexecx.sql('INSERT INTO person(name,age) VALUES(?,?)').execute('lisi', 26)
    print(sqlexecx.sql('INSERT INTO person(name,age) VALUES(?,?)').save('网吧', 27))
    print(sqlexecx.sql('INSERT INTO person(name,age) VALUES(?,?)').save_select_key(select_key, '网吧', 27))

    print(sqlexecx.sql('INSERT INTO person(name,age) VALUES(:name, :age)').save(name='zhaoliu', age=45))
    print(sqlexecx.sql('INSERT INTO person(name,age) VALUES(:name, :age)').save_select_key(select_key, name='zhaoliu', age=45))

    print(sqlexecx.sql('select * from person').select())
    print(sqlexecx.sql('select * from person').select_one())

    print(sqlexecx.sql('select id, name, age from person').query())
    print(sqlexecx.sql('select id, name, age from person where name = ?').query_one('lisi'))
    print(sqlexecx.sql('select id, name, age from person where name = :name').query_one(name='lisi'))

    print(sqlexecx.sql('select count(1) from person').get())

    print(sqlexecx.sql('select id, name, age from person where name = ?').page(2, 2).query('lisi'))
    print(sqlexecx.sql('select id, name, age from person where name = ?').page(2, 2).select('lisi'))
    print(sqlexecx.sql('select id, name, age from person where name = :name').page(2, 2).query(name='lisi'))
    print(sqlexecx.sql('select id, name, age from person where name = :name').page(2, 2).select(name='lisi'))

    print(sqlexecx.sql('select id, name, age from person where name = ?').param('lisi').page(2, 2).query())
    print(sqlexecx.sql('select id, name, age from person where name = ?').param('lisi').page(2, 2).select())
